﻿private ["_sessionID", "_parameters", "_player", "_civSlow", "_civMed", "_walker", "_positions", "_maxSpawn", "_count", "_activeFunction", "_zombieModel", "_zombiesDamage", "_nightDamage","_playerName"];

_sessionID = _this select 0;
_parameters = _this select 1;
_positions = _parameters select 0;
_player = _sessionID call ExileServer_system_session_getPlayerObject;
_playerName = name _player;

_zombiesDamage = (random 0.3) + 0.1;
_nightDamage = random 0.15;

_civSlow = ["RyanZombieC_man_1slow","RyanZombieC_man_polo_1_Fslow","RyanZombieC_man_polo_2_Fslow","RyanZombieC_man_polo_4_Fslow","RyanZombieC_man_polo_5_Fslow","RyanZombieC_man_polo_6_Fslow","RyanZombieC_man_p_fugitive_Fslow","RyanZombieC_man_w_worker_Fslow","RyanZombieC_man_hunter_1_Fslow"];

_civMed = ["RyanZombieC_man_1medium","RyanZombieC_man_polo_1_Fmedium","RyanZombieC_man_polo_2_Fmedium","RyanZombieC_man_polo_4_Fmedium","RyanZombieC_man_polo_5_Fmedium","RyanZombieC_man_polo_6_Fmedium","RyanZombieC_man_p_fugitive_Fmedium","RyanZombieC_man_w_worker_Fmedium","RyanZombieC_man_hunter_1_Fmedium"];

_walker = ["RyanZombieC_man_1walker","RyanZombieC_man_polo_1_Fwalker","RyanZombieC_man_polo_2_Fwalker","RyanZombieC_man_polo_4_Fwalker","RyanZombieC_man_polo_5_Fwalker","RyanZombieC_man_polo_6_Fwalker","RyanZombieC_man_p_fugitive_Fwalker","RyanZombieC_man_w_worker_Fwalker","RyanZombieC_scientist_Fwalker","RyanZombieC_man_hunter_1_Fwalker","RyanZombieC_man_pilot_Fwalker","RyanZombieC_journalist_Fwalker","RyanZombieC_Oresteswalker","RyanZombieC_Nikoswalker"];

if (isNull _player) exitWith {};

ryanzombiesdisablescript = true;
Ryanzombieslogicroam = true;
Ryanzombieshealth = 0.9;

if ((daytime > 17) && (daytime < 6)) then
{
	Ryanzombieslimit = 100;
	Ryanzombiesdamage = _zombiesDamage;
}
else
{
	Ryanzombieslimit = 200;
	Ryanzombiesdamage = _zombiesDamage + _nightDamage;
};

_activeFunction = count diag_activeSQFScripts;

_group = createGroup WEST;

{
	if ((random 1 > 0.98) && (_activeFunction < 150)) then
	{
		_zombieType = selectRandom
		[
			_civSlow,
			//_civMed,
			_walker
		];

		_zomebieModel = selectRandom _zombieType;

		_money = round (random 15);

		_zombie = _group createUnit [_zomebieModel,_x,[],0,"NONE"];

		_zombie setdammage 0.7;
		_zombie setspeaker "NoVoice";
		_zombie enableFatigue false;
		_zombie setbehaviour "CARELESS";
		_zombie setunitpos "UP";
		_zombie setmimic "safe";

		_face = selectRandom [
			"RyanZombieFace1",
			"RyanZombieFace2",
			"RyanZombieFace3",
			"RyanZombieFace4",
			"RyanZombieFace5",
			"RyanZombieFace6"
		];

		_zombie setface _face;
		removegoggles _zombie;

		_zombie setVariable ["AfterlifeServerZombieSpawnedAt", time + 1200];
		_zombie setVariable ["ExileMoney", _money, true];
		_zombie setVariable ["AfterlifeServerZombieSpawnedPos", _x];

		AfterlifeServerSimulatedUnit pushBack _zombie;

		_zombie addMPEventHandler
		["MPKilled",
			{
				private ["_victim", "_killer", "_exp", "_newExp", "_killSummary"];

				_victim = _this select 0;
				_killer = _this select 1;
				_killingPlayer = _killer call ExileServer_util_getFragKiller;

				[_victim] joinSilent AfterlifeServerDeadUnitGroup;

				AfterlifeServerSimulatedUnit = AfterlifeServerSimulatedUnit - [_victim];
				AfterlifeServerIdleUnit = AfterlifeServerIdleUnit - [_victim];

				_exp = _killingPlayer getVariable ["ExileScore", 0];
				_newExp = _exp + 20;

				_killingPlayer setVariable ["ExileScore", _newExp];

				_killSummary = [];
				_killSummary pushBack ["丧尸击杀", 20];

				[_killingPlayer, "showFragRequest", [_killSummary]] call ExileServer_system_network_send_to;

				format["setAccountScore:%1:%2", _newExp, getPlayerUID _killingPlayer] call ExileServer_system_database_query_fireAndForget;

				_killingPlayer call ExileServer_object_player_sendStatsUpdate;
			}
		];

		_zombie addEventHandler
		["FiredNear",
			{
				_this spawn AfterlifeServer_zombie_event_shotsDetected;
			}
		];

		AfterlifeServerIdleUnit pushBack _zombie;

	};
} forEach _positions;
